import time
from wordpress_project.base.base_page import Tools

class reg_tool(Tools):
    """页面元素定位"""
    reg_url = "http://192.168.0.125:9009/wp-login.php?action=register"
    username_ele = '[id="user_login"]'
    email_ele = '[id="user_email"]'
    button_ele = '[name="wp-submit"]'
    success_ele = '[class="message"]'
    fail_ele = '[id="login_error"]'

    def reg_action(self,usr,email):
        self.log(f'正在进行注册操作，用户名为{usr},邮箱为{email}')
        # 在方法中，调用同一个类的其他方法，  self.方法名 , 在方法中，调用类的变量 self.变量名
        self.visit(self.reg_url)
        self.by_css(self.username_ele).send_keys(usr)
        time.sleep(0.5)
        self.by_css(self.email_ele).send_keys(email)
        time.sleep(0.5)
        self.by_css(self.button_ele).click()
        time.sleep(0.5)
        self.img() # 调用截图


    def get_success_msg(self):
        return self.by_css(self.success_ele).text

    def get_fail_msg(self):
        return self.by_css(self.fail_ele).text

